import sympy, sys

#TODO: review EasyFunction and write some comments   
class EasyFunction:
    def __init__(self, *args):      
        self.namespace = {}
        self.arguments = []
        for var in args[:-1]:
            x = sympy.Symbol(var)
            self.namespace[var] = x
            self.arguments.append(var)
            
        self.expression = args[-1]

    def __call__(self, *args):
        scope = sys._getframe(1).f_globals.copy()
        scope.update(sys._getframe(1).f_locals.copy())
        expression = eval(self.expression, scope, self.namespace)
        for i in range(len(self.arguments)):
            expression = expression.subs(self.arguments[i], args[i])
        return expression